package com.esri.core.geometry;

import com.esri.core.internal.util.d;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class GeographicTransformation {
    private static final String a = "wkid";
    private static final String b = "latestWkid";
    private static final String c = "wkt";
    private static final String d = "transformForward";
    private String g;
    private int e = -1;
    private int f = -1;
    private boolean h = true;

    private GeographicTransformation() {
    }

    public static GeographicTransformation create(int i, boolean z) {
        if (i < 1) {
            throw new IllegalArgumentException("Failed to create geographic transformation. Given WKID is invalid.");
        }
        String nativeGetGeoTx = GeometryEngineCore.nativeGetGeoTx(i, null, z);
        if (nativeGetGeoTx == null) {
            throw new RuntimeException("Failed to create geographic transformation. Given WKID is invalid.");
        }
        try {
            return fromJson(nativeGetGeoTx);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static GeographicTransformation create(int i) {
        return create(i, true);
    }

    public static GeographicTransformation create(String str, boolean z) {
        if (str == null || str.trim().isEmpty()) {
            throw new IllegalArgumentException("Failed to create geographic transformation. Given WKT is invalid.");
        }
        String nativeGetGeoTx = GeometryEngineCore.nativeGetGeoTx(-1, str, z);
        if (nativeGetGeoTx == null) {
            throw new RuntimeException("Failed to create geographic transformation. Given WKT is invalid.");
        }
        try {
            return fromJson(nativeGetGeoTx);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public static GeographicTransformation create(String str) {
        return create(str, true);
    }

    public int getWkid() {
        return this.e;
    }

    public int getLatestWkid() {
        return this.f;
    }

    public String getWkt() {
        if (this.g == null) {
            this.g = a();
        }
        return this.g;
    }

    public boolean isTransformForward() {
        return this.h;
    }

    public String toJson() {
        StringBuilder sb = new StringBuilder();
        sb.append("{");
        sb.append("\"wkid\":");
        sb.append(this.e);
        if (this.f > 0) {
            sb.append(",");
            sb.append("\"latestWkid\":");
            sb.append(this.f);
        }
        sb.append(",");
        sb.append("\"transformForward\":");
        sb.append(this.h);
        if (this.g != null) {
            sb.append(",");
            sb.append("\"wkt\":");
            sb.append("\"" + this.g.replace("\"", "\\\"").toLowerCase() + "\"");
        }
        sb.append("}");
        return sb.toString();
    }

    public static GeographicTransformation fromJson(String str) throws Exception {
        if (str == null) {
            return null;
        }
        JsonParser c2 = d.c(str);
        GeographicTransformation fromJson = fromJson(c2);
        c2.close();
        return fromJson;
    }

    public static GeographicTransformation fromJson(JsonParser jsonParser) throws Exception {
        if (d.c(jsonParser)) {
            GeographicTransformation geographicTransformation = new GeographicTransformation();
            while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
                String currentName = jsonParser.getCurrentName();
                if (a.equals(currentName)) {
                    jsonParser.nextToken();
                    geographicTransformation.e = jsonParser.getIntValue();
                } else if (b.equals(currentName)) {
                    jsonParser.nextToken();
                    geographicTransformation.f = jsonParser.getIntValue();
                } else if (c.equals(currentName)) {
                    jsonParser.nextToken();
                    geographicTransformation.g = jsonParser.getText();
                } else if (d.equals(currentName)) {
                    jsonParser.nextToken();
                    geographicTransformation.h = jsonParser.getBooleanValue();
                } else {
                    jsonParser.skipChildren();
                }
            }
            return geographicTransformation;
        }
        return null;
    }

    public String toString() {
        return "GeographicTransformation [WKID: " + this.e + ", Transform Forward: " + this.h + "]";
    }

    private String a() {
        int i = this.e;
        if (i > 0) {
            return GeometryEngineCore.nativeGetTransformationWktxt(i);
        }
        return null;
    }
}
